////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017-2018 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: ParameterParser V1.1.4
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxflashdriver.cpp
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "camxflashdriver.h"
#include "parametersetmanager.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FlashDriverDataClass::FlashDriverDataClass(
    const CHAR* name)
    : ParameterModule(name, MAJOR, MINOR, PATCH, 0, 0, 0, 0)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(flashName);
    PARAMETER_INITIALIZE(flashDriverType);
    PARAMETER_INITIALIZE(powerUpSequenceExists);
    PARAMETER_INITIALIZE(powerUpSequenceID);
    PARAMETER_INITIALIZE(powerUpSequence);
    PARAMETER_INITIALIZE(powerDownSequenceExists);
    PARAMETER_INITIALIZE(powerDownSequenceID);
    PARAMETER_INITIALIZE(powerDownSequence);
    PARAMETER_INITIALIZE(i2cInfoExists);
    PARAMETER_INITIALIZE(i2cInfoID);
    PARAMETER_INITIALIZE(i2cInfo);
    PARAMETER_INITIALIZE(flashInformationExists);
    PARAMETER_INITIALIZE(flashInformationID);
    PARAMETER_INITIALIZE(flashInformation);
    PARAMETER_INITIALIZE(numberOfFlashs);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FlashDriverDataClass::FlashDriverDataClass(
    const CHAR* name,
    UINT32 modeId,
    UINT16 mode,
    UINT16 subMode,
    UINT32 group)
    : ParameterModule(name, MAJOR, MINOR, PATCH, modeId, mode, subMode, group)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(flashName);
    PARAMETER_INITIALIZE(flashDriverType);
    PARAMETER_INITIALIZE(powerUpSequence);
    PARAMETER_INITIALIZE(powerDownSequence);
    PARAMETER_INITIALIZE(i2cInfo);
    PARAMETER_INITIALIZE(flashInformation);
    PARAMETER_INITIALIZE(numberOfFlashs);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FlashDriverDataClass::~FlashDriverDataClass()
{
    UnloadFlashDriverData(this);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// GetName
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CHAR* FlashDriverDataClass::GetName(
    const CHAR* type)
{
    const CHAR* name = type;
    CHAR temp[ParameterFileSymbolTableEntry::TYPE_LEN + 1];
    if (PARAMETER_STRCMP(type, ParameterFileSymbolTableEntry::GetType(temp, "flashDriverData")) == 0)
    {
        name = "flashDriverData";
    }
    return name;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load FlashI2CInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL FlashDriverDataClass::LoadFlashI2CInformation(
    ParameterFileSymbolTableEntry* entry,
    FlashI2CInformation* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt16(&structure->slaveAddress);
    result = result && entry->ReadUInt32(&structure->regAddrType);
    result = result && entry->ReadUInt32(&structure->regDataType);
    structure->i2cFrequencyMode = (I2CFrequencyMode)entry->ReadEnum(&result);
    result = result && camxsensorcommonClass::LoadSettingsInfo(entry, &structure->flashInitSettings);
    result = result && camxsensorcommonClass::LoadSettingsInfo(entry, &structure->flashOffSettings);
    result = result && camxsensorcommonClass::LoadSettingsInfo(entry, &structure->flashLowSettings);
    result = result && camxsensorcommonClass::LoadSettingsInfo(entry, &structure->flashHighSettings);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load TriggerInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL FlashDriverDataClass::LoadTriggerInformation(
    ParameterFileSymbolTableEntry* entry,
    TriggerInformation* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt32(&structure->maxFlashCurrent);
    result = result && entry->ReadUInt32(&structure->maxTorchCurrent);
    result = result && entry->ReadUInt32(&structure->maxFlashDuration);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load FlashInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL FlashDriverDataClass::LoadFlashInformation(
    ParameterFileSymbolTableEntry* entry,
    FlashInformation* structure)
{
    BOOL result = TRUE;

    // Reading structure->triggerInfo from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->triggerInfoCount);
        structure->triggerInfoID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result)
        {
            structure->triggerInfo   = PARAMETER_NEW TriggerInformation[structure->triggerInfoCount];
        }
        if (!result || structure->triggerInfo == NULL)
        {
            structure->triggerInfoCount = 0;
        }
        for (UINT32 i = 0; result && i < structure->triggerInfoCount; i++)
        {
            result = result && LoadTriggerInformation(pointerEntry1, &structure->triggerInfo[i]);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load FlashDriverData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL FlashDriverDataClass::LoadFlashDriverData(
    ParameterFileSymbolTableEntry* entry,
    FlashDriverData* structure)
{
    BOOL result = TRUE;
    result = result && Loadmodule_versionStruct(entry, &structure->module_version);

    // Reading structure->flashName from the symbol table
    {
        UINT32 flashNameCount = 0;
        result = result && entry->ReadUInt32(&flashNameCount);
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        structure->flashName = NULL;
        if (result)
        {
            pointerEntry1->ReadString(&structure->flashName, flashNameCount);
        }
    }
    structure->flashDriverType = (FlashDriverType)entry->ReadEnum(&result);

    // Reading structure->powerUpSequence from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->powerUpSequenceExists);
        structure->powerUpSequenceID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->powerUpSequenceExists)
        {
            result = result && camxsensorcommonClass::LoadPowerSequenceInfo(pointerEntry1, &structure->powerUpSequence);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->powerUpSequence);
        }
    }

    // Reading structure->powerDownSequence from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->powerDownSequenceExists);
        structure->powerDownSequenceID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->powerDownSequenceExists)
        {
            result = result && camxsensorcommonClass::LoadPowerSequenceInfo(pointerEntry1, &structure->powerDownSequence);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->powerDownSequence);
        }
    }

    // Reading structure->i2cInfo from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->i2cInfoExists);
        structure->i2cInfoID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->i2cInfoExists)
        {
            result = result && LoadFlashI2CInformation(pointerEntry1, &structure->i2cInfo);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->i2cInfo);
        }
    }

    // Reading structure->flashInformation from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->flashInformationExists);
        structure->flashInformationID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->flashInformationExists)
        {
            result = result && LoadFlashInformation(pointerEntry1, &structure->flashInformation);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->flashInformation);
        }
    }
    result = result && entry->ReadUInt16(&structure->numberOfFlashs);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load module_versionStruct
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL FlashDriverDataClass::Loadmodule_versionStruct(
    ParameterFileSymbolTableEntry* entry,
    FlashDriverData::module_versionStruct* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadInt32(&structure->major_revision);
    result = result && entry->ReadInt32(&structure->minor_revision);
    result = result && entry->ReadInt32(&structure->incr_revision);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload FlashI2CInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FlashDriverDataClass::UnloadFlashI2CInformation(
    FlashI2CInformation* structure)
{
    camxsensorcommonClass::UnloadSettingsInfo(&structure->flashInitSettings);
    camxsensorcommonClass::UnloadSettingsInfo(&structure->flashOffSettings);
    camxsensorcommonClass::UnloadSettingsInfo(&structure->flashLowSettings);
    camxsensorcommonClass::UnloadSettingsInfo(&structure->flashHighSettings);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload FlashInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FlashDriverDataClass::UnloadFlashInformation(
    FlashInformation* structure)
{
    PARAMETER_DELETE[] structure->triggerInfo;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload FlashDriverData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FlashDriverDataClass::UnloadFlashDriverData(
    FlashDriverData* structure)
{
    PARAMETER_DELETE[] structure->flashName;
    camxsensorcommonClass::UnloadPowerSequenceInfo(&structure->powerUpSequence);
    camxsensorcommonClass::UnloadPowerSequenceInfo(&structure->powerDownSequence);
    UnloadFlashI2CInformation(&structure->i2cInfo);
    UnloadFlashInformation(&structure->flashInformation);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Parse symbol table entry, and return a new object
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ParameterModule* FlashDriverDataClass::Parse(
    ParameterSetManager* manager,
    ParameterFileSymbolTableEntry* entry) const
{
    FlashDriverDataClass* cls = NULL;

    if (PARAMETER_STRCMP(Type, entry->Type) == 0 && Major == entry->Major &&
        Minor == entry->Minor && Patch == entry->Patch)
    {
        cls = PARAMETER_NEW FlashDriverDataClass(GetName(entry->Type), 
            entry->ModeId, entry->Mode, entry->SubMode, entry->Group);
        if (cls != NULL)
        {
            BOOL result = TRUE;

            cls->SymbolTableID = entry->ID;
            cls->ID            = entry->ID;

            result = result && LoadFlashDriverData(entry, cls);

            if (!result)
            {
                PARAMETER_DELETE cls;
                cls = NULL;
            }
        }
    }
    return (ParameterModule*)cls;
}


CAMX_NAMESPACE_END
